import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;

public class DataErr {
	ArrayList<Double>  conc;
	ArrayList<Double>  dose;
	ArrayList<Double>  volume;
	ArrayList<Double>  weight;
	ArrayList<Double>  rate;
	public Iterator<Double> conc_err; 
	public Iterator<Double> dose_err; 
	public Iterator<Double> volume_err; 
	public Iterator<Double> rate_err; 

	DataErr(Input nI) {
		if(nI.rate != -1) {
			rate = new ArrayList<Double>(interchange(nI.rate));
			System.out.println("rate vals " + nI.rate);
			for(Double d:rate) {
				System.out.println(d);
			}
			System.out.println();
			rate_err = rate.iterator();
		}
		if(nI.volume != -1) {
			volume = new ArrayList<Double>(interchange(nI.volume));
			System.out.println("volume vals " + nI.volume);
			for(Double d:volume) {
				System.out.println(d);
			}
			System.out.println();
			volume_err = volume.iterator();
		}
		if(nI.dose != -1) {
			dose = new ArrayList<Double>(interchange(nI.dose));
			System.out.println("dose vals "  + nI.dose);
			for(Double d:dose) {
				System.out.println(d);
			}
			System.out.println();
			dose_err = dose.iterator();
		}
		if(nI.rate != -1) {
			conc = new ArrayList<Double>(interchange(nI.conc));
			System.out.println("conc vals " + nI.conc);
			for(Double d:conc) {
				System.out.println(d);
			}
			System.out.println();
			conc_err = conc.iterator();
		}
	}
	
	double next_err() {
		while(rate_err.hasNext()) {
			return rate_err.next();
		}
		while(volume_err.hasNext()) {
			return rate_err.next();
		}
		while(conc_err.hasNext()) {
			return rate_err.next();
		}
		while(dose_err.hasNext()) {
			return rate_err.next();
		}
		return -1;	
	}
	
	Iterator<Integer> currentpres = Baxterpump.Mode.Modes.iterator();
	int currentp;
	
	
	ArrayList<Double> interchange(double val)
	{
		LinkedList<Integer> digits = new LinkedList<Integer>();
		ArrayList<Double> res = new ArrayList<Double>();
		digits  = getdigits(val);
		Integer[] arr = new Integer[digits.size()];
		digits.toArray(arr);
		System.out.println("Digits after decimal: " + arr[0]);
		System.out.print("Digits are: ");
		for(int i = 1; i < digits.size(); i++) {
			System.out.print(arr[i]);
		}
		System.out.println();
		int decimals = arr[0];
		int power = digits.size()-1-decimals;
		for(int i = 1; i < digits.size()-1; i++) {
			digits.toArray(arr);
			int tmp0 = arr[i];
			arr[i] = arr[i+1];
			arr[i+1] = tmp0;
			double inter = 0;
				for(int j = 1; j < digits.size(); j++) {
					inter += arr[j]*Math.pow(10, (power-j));
				}
			res.add(inter);
		}
		double dec;
		if(decimals != 0) {
			dec = val*Math.pow(10, decimals);
			res.add(dec);
			dec = val/10;
			res.add(dec);
			if(decimals != 1) {
				dec = val*10;				
				res.add(dec);
			}
		}
		
		Iterator<Double> itr = res.iterator();
		System.out.println("Interchanged nums: ");
		while(itr.hasNext()) {
			System.out.println(itr.next());
		}
		return res;
	}
	
	LinkedList<Integer> getdigits(double val)
	{
		String str = Double.toString(val);
		System.out.println("string rep: " + str);
		LinkedList<Integer> digits = new LinkedList<Integer>();
		int count = 0;
		for(int i = 0; i < str.length(); i++) {
			char c = str.charAt(i);
			if(c == '.') {
				int j;
				for(j = i+1; j < str.length(); j++) {
					count++;
					c = str.charAt(j);
					digits.add(Character.getNumericValue(c));
				}
				if(count == 1 && digits.getLast() == 0){
					count = 0;
					digits.removeLast();
				}
				break;
			}
			digits.add(Character.getNumericValue(c));
		}
		digits.push(count);
		return digits;
	}
}
